home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE3 / POWERBASE / DOCS / Ch12-Scrip < prev    next >
Text File  |  2001-03-16  |  14KB  |  269 lines

  1. ====================
  2. Ch 12 − Script Files
  3. ====================
  4.  
  5. Powerbase incorporates a script language which lets you control many
  6. features from a script file. Using script files you can automate jobs which
  7. need to be done frequently, print jobs being the most obvious example. 
  8. Script files are plain text files (created with Edit, StrongEd etc.) and are
  9. executed by dragging them to the Powerbase record window. All commands in a
  10. script file must be in upper-case, preceded by “!”, and may be followed by
  11. parameters (which are not case-sensitive), separated from the command by a
  12. single space. A complete list of commands follows. Parameters in square
  13. brackets are optional. Where commands simply control the status of options
  14. switches (e.g. !CASE, !UPPER) the parameter is either ON or OFF.
  15.  
  16. !SCRIPT Since scripts are just text files there has to be a way for
  17. Powerbase to recognise them. All script files must therefore start with a
  18. line beginning with !SCRIPT. Prior to v.8 !SCRIPT POWERBASE was required;
  19. you may still add POWERBASE but it is no longer necessary. You may use
  20. !SCRIPT END as the last line of the file but this is also optional since the
  21. script will terminate anyway when the end of the file is reached. You can
  22. make the command “chain” another script file by following it with the name
  23. of the new file, i.e. by using the form !SCRIPT <filename>. If you just give
  24. a leafname Powerbase will look for it in the database’s PrintRes directory.
  25. If it is stored anywhere else the full pathname must be supplied. This rule
  26. applies to all script commands (e.g. !DELETE, !INCLUDE) which can take a
  27. filename as a parameter. When a script file is dropped onto the record
  28. window its name will be displayed with a request for confirmation that the
  29. file is to be executed. To suppress this action use !SCRIPT QUIET as the
  30. first line.
  31.  
  32. !COMMENT <string> may be used to insert comments in a script file. The rest
  33. of the line is ignored. 
  34.  
  35. !MESSAGE <string> will display a user-defined message in a small window to
  36. keep the user informed of what’s happening during execution of a script.
  37. !MESSAGE on its own closes the message window.
  38.  
  39. !SELECTION is used to select fields for inclusion in a report. If a filename
  40. is given as a parameter Powerbase looks for a print Selection file of that
  41. name and loads it, just as if you had double-clicked on it or dragged it to
  42. the record window. (See !SCRIPT, above, for the interpretation of
  43. filenames.) Alternatively, you may supply a comma-separated list of the tags
  44. of the required fields and may include the record number, key and subfile
  45. number by placing RECORD, KEY and SUBFILE, respectively, in the list. If you
  46. supply no parameter at all the current selection will be cleared.
  47.  
  48. !PRINTOPTS <filename> loads a Print options file, setting the options just
  49. as if the the file had been double-clicked or dragged to the record window. 
  50. Without a filename it sets the default options.
  51.  
  52. !SUBFILES <n>[,<n1>,<n2>...] selects the subfile(s) which will be searched
  53. in order to create a report.
  54.  
  55. !CASE turns the Case switch on the Query panel ON and OFF. 
  56.  
  57. !QUERY [filename\]<search formula> is used to print a report. It returns the
  58. same result as entering a search formula in the Match window and clicking
  59. Print. If you first issue a !DESTINATION FILE command you can use a list of
  60. !QUERY commands to create a batch of reports as text files. If you omit the
  61. optional filename each file will be created in PrintJobs using the search
  62. formula (or part of it) as the filename. If you supply a name containing $
  63. it is assumed to be a full pathname and will be used to create the file. Any
  64. other name causes the file to be created in PrintJobs or in a subdirectory
  65. (which must exist) of Print Jobs. Note the backslash between the filename
  66. and search formula; this tells Powerbase where the one ends and the other
  67. begins. !CASE  also affects the behaviour of this command if issued
  68. beforehand.
  69.  
  70. !SAVE <filename> may be used to save a file which has been created in a
  71. window. It is only useful after a !QUERY command for which the destination
  72. is Window.
  73.  
  74. !CSV  [filename\]<search formula> is similar to !QUERY but produces a CSV
  75. file instead. The CSV option settings are observed.  A prior !DESTINATION
  76. command is unnecessary in this case.
  77.  
  78. !INCLUDE, !EXCLUDE, !CLEAR may conveniently be treated together. They have
  79. the same effects as the controls on the Mark pane attached to the bottom of
  80. the record window. !INCLUDE <key>[,<key>,<key>...] has exactly the same
  81. effect as ticking the check box on the Mark pane for records with the
  82. associated primary keys. !EXCLUDE (same syntax) has the same effect as
  83. marking with a cross, which is what happens when the alternative option from
  84. the pane’s pop-up menu is chosen. !CLEAR clears all marks. As an alternative
  85. to a comma-separated list of keys you may supply a filename. The file should
  86. be a plain text file with one primary key on each line. See !SCRIPT for the
  87. interpretation of filenames.
  88.  
  89.                                 - 54 -
  90.  
  91. !FORMAT <string> where <string> is Horizontal, Vertical, Label or Table sets
  92. the print format. If any other parameter is used, or !FORMAT is issued by
  93. itself, the Horizontal format is used.
  94.  
  95. !DESTINATION <string> where <string> is Window, File or Printer sets the
  96. destination for report printing (see 3.1).  If File is used the report is
  97. saved in PrintJobs unless a subsequent !QUERY command supplies an
  98. alternative pathname (see above).
  99.  
  100. !EXPAND ON selects the the switch which causes fields to be expanded by
  101. reference to a linked validation table. !EXPAND OFF (or just !EXPAND by
  102. itself) deselects the switch.
  103.  
  104. !DATE turns date and time stamping ON and OFF.
  105.  
  106. !UPPER forces upper-case printing ON, normal upper/lower case printing
  107. otherwise. 
  108.  
  109. !HEADER, !FOOTER determine whether  header/footer information (see 3.10) is
  110. printed on reports.
  111.  
  112. !FIRST when followed by ON causes the header to appear on the first page
  113. only. (Footer information only appears on the final page anyway.)
  114.  
  115. !SHRINK determines whether surplus “white space” is removed from between the
  116. columns of reports in Horizontal format. 
  117.  
  118. !HEADINGS D causes descriptors to be used as field identifiers in a report.
  119. !HEADINGS T, or without any parameter, causes tags to be used.
  120.  
  121. !TITLE <string> uses <string> as a title on subsequently printed reports. 
  122.  
  123. !PAGE <n> sets the page length for reports to n lines. 64 is probably
  124. correct for A4 (but see 3.10). 
  125.  
  126. !SPACER <string> specifies the string to be used to separate columns of
  127. printed data in reports using Horizontal or Table format (see 3.10). 
  128.  
  129. !TEXTWIDTH <n> specifies the maximum width in characters for Memo and Text
  130. block fields in reports.
  131.  
  132. !ORIENTATION <LANDSCAPE, SIDEWAYS> changes the paper orientation for
  133. hard-copy printing from the default: !ORIENTATION PORTRAIT or UPRIGHT turns
  134. it back again.
  135.  
  136. !HEADERFONT, !BODYFONT <fontname> set the fonts for headers and footers and
  137. for body text in hard-copy printing. Names should be of the form
  138. Homerton.Medium, Trinity.Bold.Italic etc. The font must, of course, be known
  139. to the font-manager.
  140.  
  141. !FONTSIZE sets the size, in points, of the fonts used for hard-copy
  142. printing.
  143.  
  144. !LMARGIN, !RMARGIN, !TMARGIN, !BMARGIN <n> set the print margins for
  145. hard-copy printing. The units default to mm unless specified by appending
  146. mm, in or pt to the number.
  147.  
  148. !PMARGINS cancels the margin settings in the Printer Setup window and uses
  149. the printer driver’s default margins instead. 
  150.  
  151. !LINESPACE <n> sets the spacing between the baseline of one line of printed
  152. text and the next as a percentage of the font size. The default is 120%. For
  153. Table format 150% looks neater.
  154.  
  155. !TABLE <columns>,<width>,<rows> sets up the number and width of blank
  156. columns, and the number of blank rows at the end of the report, in Table
  157. format. Column width is in mm but may be changed as for margins (see above).
  158. You need not specify all the parameters; current values will be used if any
  159. are omitted. You may, for example, specify 6 blank rows and nothing else by
  160. using !LABEL ,,6. Note the commas.
  161.  
  162. !LABEL <n>,<w>,<h>,<str1>,<str2>,<s>,<su>,<bl>,ON/OFF determines the setup
  163. for label-printing where: n=number of labels across the page, w and h are
  164. the width and height of label (units may be specified as for margins and
  165. column widths), str1 and str2 are the optional fixed first and last lines
  166. and s=number of label at which printing on first page is to start. su and bl
  167. are field tags. If field bl is blank then field su will be printed instead.
  168. The final parameter specifies whether the primary key is to be printed on
  169. the label. As with !TABLE you need only specify the values you wish to
  170. change, but watch those commas!
  171.  
  172. !COPIES <n> specifies the number of copies to be printed
  173.  
  174. !SORT <n> specifies a column on which the report is to be sorted before
  175. printing. The tag of a field included in the report may be specified instead
  176. of a column number. The !SORT must appear before !QUERY in the script file.
  177. It cannot be used when the output destination is File.
  178.  
  179. !IMPRESSION is used in conjunction with !QUERY to generate a report in
  180.  
  181.                                 - 55 -
  182.  
  183. text-file format, allows you to insert Impression DDF* commands at the start
  184. of the text-file. A script may, for example, execute a series of !QUERY
  185. commands and the resulting files are to be all selected together and dragged
  186. into an Impression document. To make each file go into a new frame you need
  187. to make each begin with {nextframe}. This can be achieved by placing the
  188. script command !IMPRESSION {nextframe} before the first !QUERY. You do not,
  189. however, want {nextframe} to begin the first file created, or the Impression
  190. document will have a blank frame on its first page. To suppress the effect
  191. on the first file use: !IMPRESSION {nextframe} Not first. There must be a
  192. space between the “}” and the “N”, but the “Not first” string isn’t case
  193. sensitive.
  194.  
  195. !DELETE <key>[,<key>,<key>...] deletes record(s) having the supplied primary
  196. key(s). As an alternative to the key or key-list you may supply the name of
  197. a text-file containing the required keys, one to a line. The filename will
  198. be interpreted as described above for !SCRIPT <filename>. The command can
  199. delete records in any or all of the six subfiles, not just the current
  200. subfile
  201.  
  202. !INSERT is the counterpart of !DELETE. Useful in similar circumstances. In
  203. this case the command must occupy a line by itself and be followed by the
  204. record to insert, one field to a line. It is the user’s responsibility to
  205. ensure that the lines are not too long for the database fields into which
  206. they are placed and that the number of lines following each !INSERT is the
  207. same as the number of fields in the record. Don’t forget to leave blank
  208. lines for empty fields!  Records will be inserted into the
  209. currently-selected subfile.
  210.  
  211. !MOVE has the same syntax as !DELETE but moves records from their present
  212. subfile to the next in sequence, regardless of the currently-displayed
  213. subfile; e.g. a record in subfile 2 will be moved to subfile 3.
  214.  
  215. !CHANGE <field tag>,<old contents>,<new contents>[,<search formula>] allows
  216. global changes to be made. The command functions like the Global changes
  217. menu choice (see 2.5.5).
  218.  
  219. !OBEY <string> can be made to do anything which a *command can do. e.g.
  220. !OBEY Delete <filename> will delete the named file. !OBEY <filename> will
  221. attempt to *Run the file. By supplying the pathname of a Powerbase database
  222. you can close the existing database and open a new one.
  223.  
  224. !KEY <index name> where the specified index name appears on the menu of
  225. loaded indexes will make that the currently active index. If no parameter is
  226. given the primary key index is selected.
  227.  
  228. !INDEX <tag>[,<tag>,<tag>...] constructs an index on the field whose tag is
  229. first in the list and makes it the currently active index. If further tags
  230. are supplied each is treated in exactly the same way. Using the Elements
  231. database, for example, the command !INDEX Z,GP would index first on the
  232. Atomic number (Z), then on the Group field (GP) with the Z index active. The
  233. database is left with GP as the active index and a report of the whole
  234. database shows the records ordered by Group but, within each group, the
  235. records are in order of Atomic number; a sort within a sort. The whole field
  236. (with spaces ignored) is used as the key unless you specify a shorter key by
  237. placing a number before the tag, e.g. 5NAME for the leftmost five letters.
  238.  
  239. Powerbase “remembers” the names of the indices created by the most recent
  240. !INDEX command and will delete them if you issue !INDEX with no parameters.
  241.  
  242. !FILTER <search formula> has the same effect as entering a search formula in
  243. the Filter window. The Filter window isn’t opened but the Filter switch on
  244. the keypad (or on the record screen if there’s a Filter switch there) is
  245. turned on and the first matching record is displayed. !FILTER on its own
  246. cancels the filter.
  247.  
  248. !STARTAT <tag> sets the field at which editing begins and places the caret
  249. in that field. If no parameter is given, or if the designated field doesn’t
  250. exist or isn’t writable, editing starts at the first writable field.
  251.  
  252. Requesting user input from script files
  253. =======================================
  254. This is best illustrated with an example. !FILTER GP=1 will use GP=1 as a
  255. search formula. However, !FILTER Search formula? behaves quite differently.
  256. A small window pops up saying “Search formula?” with a writable icon into
  257. which you enter the formula then click OK or type Return. This applies to
  258. all script commands. Instead of putting the parameter itself in the script,
  259. supply a prompt followed by a question mark and the parameter and will be
  260. requested and used with the command.  Why would you want to do this? You
  261. might use a script to print a report in Table format but not always want the
  262. same number of blank columns and rows. You can request these with !TABLE
  263. Columns?,,Extra rows?,. Note the double comma (column width is not changed)
  264. and the comma after “?”. Powerbase checks the parameter string for a
  265. concluding “?” which, if found, causes the whole string to be treated as a
  266. prompt. This is fine for commands like !TITLE which take only one parameter
  267. but those which take multiple parameters need the concluding comma.
  268.  
  269.                                 -56 -